package com.zhaopin.file;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

/**
 * @author Administrator
 * @create 2019-05-20 16:44
 */
public class HandleFileRankingword {
    public static void main(String[] args) throws IOException {

        //首先读取 文件大
        // 然后读取 文件小
        String bigFile = "E:\\data4\\rankingword.new.txt\\rankingword.new.txt";
        String smallFile = "E:\\data4\\rankingword.new.txt\\rankinging_yushangxian.txt";
        String writeFilePath = "E:\\data4\\rankingword.new.txt\\bigId.txt";
        String writeSetFilePath = "E:\\data4\\rankingword.new.txt\\setBigId.txt";

        List<String> listBig = FileUtils.readLines(new File(bigFile), "utf-8");
        List<String> listSmall = FileUtils.readLines(new File(smallFile), "utf-8");

        System.out.println("big " + listBig.size());
        System.out.println("small " + listSmall.size());
        System.out.println("1");

        List<String> bigIdList = new ArrayList<>(2);
        for (String s : listBig) {
            JSONObject jsonObject = JSON.parseObject(s);
            bigIdList.add(jsonObject.getString("id"));
        }
        System.out.println("2");
        List<String> smallIdList = new ArrayList<>(2);
        for (String s : listSmall) {
            JSONObject jsonObject = JSON.parseObject(s);
            smallIdList.add(jsonObject.getString("id"));
        }
        System.out.println("3");
        PrintWriter printWriter = new PrintWriter(new File(writeFilePath), "utf-8");
        PrintWriter printWriter2 = new PrintWriter(new File(writeSetFilePath), "utf-8");



        int i = 0;
        Set<Integer> set =new TreeSet<>();
        for (Object s : bigIdList) {
            set.add(Integer.parseInt(s.toString()));
            printWriter.println(s);
            System.out.println(i++);
        }


        int j = 0;
        for (Object o : set) {
         printWriter2.println(o);
            System.out.println(j++);
        }





//        int i = 0;
//        for (String s : bigIdList) {
//            if (!smallIdList.contains(s)) {
//                System.out.println(i +"--------" +  s);
//                printWriter.println(s);
//            } else {
//                System.out.println(i);
//            }
//            i++;
//        }

        printWriter.flush();
        printWriter.close();
        printWriter2.flush();
        printWriter2.close();
    }
}
